/**
 * 
 */
package com.db.stockexchange.server.orderbook;


/**
 * @author Rayman
 * Price in order book
 */
public class Price implements Comparable<Object> {
	float price;
	
	public Price(float price) {
		this.price = price;
	}
	
	public float getValue() {
		return price;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Price p = (Price) obj;

		if (Math.abs(this.price - p.price) >= OrderBook.PRICE_TICK/2)
			return false;
		return true;		
	}
	
	@Override
	public int compareTo(Object obj) {
		if (getClass() == obj.getClass()) {
			Price p = (Price) obj;
			return (Math.abs(this.price - p.price) < OrderBook.PRICE_TICK/2) ? 0 : (this.price > p.price) ? 1 : -1;			
		}
		else if (obj.getClass() == Float.class) {
			Float f = (Float) obj;
			return (Math.abs(this.price - f) < OrderBook.PRICE_TICK/2) ? 0 : (this.price > f) ? 1 : -1;				
		}
		else
			return 0;
	}
	
}
